﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using nplJobsCommon;
using nplJobs.DB;
using System.Data;
using nplJobsCommon.Common;

namespace nplJobsDAL.Select
{
    public class SelectJobList
    {
        public static List<JobList> GetList(JobList obj)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();

                cpList.Add(new CustomParameter("@LocationID", obj.LocationID, DbType.Int32));
                cpList.Add(new CustomParameter("@JobCategoryID", obj.JobCategoryID, DbType.Int32));
                cpList.Add(new CustomParameter("@JobTypeID", obj.JobTypeID, DbType.Int32));
                cpList.Add(new CustomParameter("@JobCompanyID", obj.JobCompanyID, DbType.Int32));
                cpList.Add(new CustomParameter("@Title",obj.Title,DbType.String));
                cpList.Add(new CustomParameter("@Place", obj.Place,DbType.String));
                cpList.Add(new CustomParameter("@isGovtJob", obj.isGovtJob, DbType.Boolean));
              

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spJobsList");

                List<JobList> results = new List<JobList>();
                foreach (DataRow dr in dt.Rows)
                {
                    JobList objJobList = new JobList();

                    MapperBase.GetInstance().MapItem(objJobList, dr); ;
                    results.Add(objJobList);
                }
                return results;

            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static List<JobListDetails> GetJobListDetails(JobListDetails obj, int StartIndex, int pageSize, out int numTotalRows)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();

                cpList.Add(new CustomParameter("@CategoryID", obj.CategoryID, DbType.Int32));
                cpList.Add(new CustomParameter("@What", obj.What, DbType.String));
                cpList.Add(new CustomParameter("@Where", obj.Where, DbType.String));
                cpList.Add(new CustomParameter("@DateFrom", obj.DateFrom, DbType.String));
                cpList.Add(new CustomParameter("@Location", obj.Location, DbType.String));
                cpList.Add(new CustomParameter("@JobType", obj.JobType, DbType.String));
                cpList.Add(new CustomParameter("@JobCompany", obj.Company, DbType.String));
                cpList.Add(new CustomParameter("@JobCareerLevel", obj.JobCareerLevel, DbType.String));
                cpList.Add(new CustomParameter("@StartIndex", StartIndex, DbType.Int32));
                cpList.Add(new CustomParameter("@MaxRows", pageSize, DbType.Int32));
                cpList.Add(new CustomParameter("@numTotalRows", 0, DbType.Int32));



                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref  paramval, null, "spJobListDetails");
                numTotalRows = (int)paramval;


                //object paramval = null;
                //DBHelper db = new DBHelper();
                //DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spJobListDetails");

                //MaxRows = (int)paramval;

                List<JobListDetails> results = new List<JobListDetails>();
                foreach (DataRow dr in dt.Rows)
                {
                    JobListDetails objJobList = new JobListDetails();

                    MapperBase.GetInstance().MapItem(objJobList, dr); ;
                    results.Add(objJobList);
                }
                return results;

            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static List<Job> GetJobDetails(Guid employeerId)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();
                cpList.Add(new CustomParameter("@EmployeerID", employeerId, DbType.Guid));

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spGetJobDetailsByEmployeer");

                List<Job> results = new List<Job>();
                foreach (DataRow dr in dt.Rows)
                {
                    Job objJobList = new Job();

                    MapperBase.GetInstance().MapItem(objJobList, dr);
                    results.Add(objJobList);
                }
                return results;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static List<Job> GetCategoryWiseJobDetails(string what, string where, string closing, string posted, string jobType, string careerLevel, string industry, string category, string deadlineTomorrow)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();
                cpList.Add(new CustomParameter("@What", what, DbType.String));
                cpList.Add(new CustomParameter("@Where", where, DbType.String));
                cpList.Add(new CustomParameter("@ClosingDate", closing, DbType.String));
                cpList.Add(new CustomParameter("@Posted", posted, DbType.String));
                cpList.Add(new CustomParameter("@JobType", jobType, DbType.String));
                cpList.Add(new CustomParameter("@CareerLevel", careerLevel, DbType.String));
                cpList.Add(new CustomParameter("@Industry", industry, DbType.String));
                cpList.Add(new CustomParameter("@CategoryGeneral", category, DbType.String));
                cpList.Add(new CustomParameter("@DeadlineTomorrow", deadlineTomorrow, DbType.String));

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spGetCategoryWiseJobDetails");

                List<Job> results = new List<Job>();
                foreach (DataRow dr in dt.Rows)
                {
                    Job objJobList = new Job();

                    MapperBase.GetInstance().MapItem(objJobList, dr);
                    results.Add(objJobList);
                }
                return results;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static List<Job> GetOverseasJobDetails()
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spGetOverseasJobDetails");

                List<Job> results = new List<Job>();
                foreach (DataRow dr in dt.Rows)
                {
                    Job objJobList = new Job();

                    MapperBase.GetInstance().MapItem(objJobList, dr);
                    results.Add(objJobList);
                }
                return results;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static List<Job> GetLocationWiseJobDetails(int location)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();
                cpList.Add(new CustomParameter("@Location", location, DbType.Int32));

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spGetLocationWiseJobDetails");

                List<Job> results = new List<Job>();
                foreach (DataRow dr in dt.Rows)
                {
                    Job objJobList = new Job();

                    MapperBase.GetInstance().MapItem(objJobList, dr);
                    results.Add(objJobList);
                }
                return results;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        public static Job GetJobDetails(int Id)
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();
                cpList.Add(new CustomParameter("@JobID", Id, DbType.Int32));
                
                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spGetJobDetails");

                List<Job> results = new List<Job>();
                foreach (DataRow dr in dt.Rows)
                {
                    Job objJobList = new Job();

                    MapperBase.GetInstance().MapItem(objJobList, dr); ;
                    results.Add(objJobList);
                }
                return results.Count > 0 ? results[0] : null;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}
